import Vue from 'vue'
import Router from 'vue-router'
import Home from '../components/Main.vue'
import Login from '../views/Login.vue'

Vue.use(Router)

const router = new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/login',
      name: 'login',
      component:Login,
    },
    {
      path: '/',
      name: 'main',
      component: Home,
      children:[
        {
          name: 'courseKeep',
          path: '/', //默认进入页面
          component: () => import('../views/courseManage/CourseKeep.vue')
        },
        {
          path: '/franchiseesManage',
          component: () => import('../views/franchiseesManage/FranchiseesManage.vue')
        },
        {
          name: 'group',
          path: '/group',
          component: () => import('../views/franchiseesManage/Grouping.vue')
        },
        {
          name: 'groupAdd',
          path: '/groupAdd',
          component: () => import('../views/franchiseesManage/GroupAdd.vue')
        },
        {
          name: 'courseKeep',
          path: '/courseKeep', 
          component: () => import('../views/courseManage/CourseKeep.vue')
        },
        {
          name: 'courseStatistic',
          path: '/courseStatistic',
          component: () => import('../views/courseManage/CourseStatistic.vue')
        },
        {
          name: 'courseLook',
          path: '/courseLook',
          component: () => import('../views/courseManage/CourseLook.vue')
        },
        {
          name: 'courseSend',
          path: '/courseSend',
          component: () => import('../views/courseManage/CourseSend.vue')
        },
        {
          name: 'courseSend2',
          path: '/courseSend2',
          component: () => import('../views/courseManage/CourseSend2.vue')
        },
        {
          path: '/video',
          component: () => import( '../views/videoManage/VideoManager.vue')
        },
        {
          path: '/user',
          component: () => import( '../views/userManage/UserManage.vue')
        },
        {
          path: '/news',
          component: () => import( '../views/newsManage/NewsManage.vue')
        },
        {
          path: '/banner',
          component: () => import( '../views/bannerManage/Banner.vue')
        },
        {/* 加盟商修改自己的信息 */
          path: '/userSelf',
          component: () => import( '../views/userSelf/UserSelf.vue')
        },          
      ]
    },
   
  ]
})

router.beforeEach((to, from, next) => {
  // console.log("sssss"+to.meta);
  if( to.path != '/login' && !localStorage.token){
    return next('/login')
  }
  // if( to.path != '/login' && !localStorage.userName){
  //   return next('/login')
  // }
  // if( to.path != '/login' && !localStorage.userImg){
  //   return next('/login')
  // }
  next()
})

export default router